/*
 *获取多语言，仅在本地环境执行
 */

import { getLang } from '@/utils/lang';
import ComponentsMeta from '../../AssetPack/web/web-components/components.json';

// -------- 方法 ----------
function loadLangs() {
  const langArr = require('../../public/i18n/languages_all.js');
  const i18nData = {};
  const i18nDataAll = {
    'zh-CN': {},
    'en-US': {},
    'th-TH': {},
  };
  const lang = getLang();
  const cnMap = {};
  langArr.forEach(n => {
    if (i18nData[n.key]) {
      window.showErr && window.showErr('国际化key重复', n.key);
    }
    i18nData[n.key] = n[lang];
    i18nDataAll['zh-CN'][n.key] = n['zh-CN'];
    i18nDataAll['en-US'][n.key] = n['en-US'];
    i18nDataAll['th-TH'][n.key] = n['th-TH'];
    const cn = n['zh-CN'];
    if (!cnMap[cn]) {
      cnMap[cn] = [];
    }
    cnMap[cn].push(n);
  });
  window._adoPremise.uc.languages[ComponentsMeta.i18nTag] = i18nData;
  window._adoPremise.uc.languages.VisualComponents_All = i18nDataAll;
  window._adoPremise.uc.languages.cnMap = cnMap;
  window.i18nReady = true;
}

loadLangs();
